<template>
    <div>

        <van-nav-bar title="测试方法" left-arrow @click-left="onClickLeft"/>

        <van-button type="primary" @click="onClick" block style="margin-top: 50px;">按钮1</van-button>

        <van-button type="primary" @click="onClick2" block style="margin-top: 50px;">按钮2</van-button>

        <van-button type="primary" @click="onClick3" block style="margin-top: 50px;">ipone X</van-button>

        <van-button type="primary" @click="onClick4" block style="margin-top: 50px;">ipone X 回调</van-button>


    </div>
</template>

<script>
    export default {
        name: "func",
        methods: {
            onClickLeft(){

            },
            onClick(){
                this.CallApp('goBack',{},function(data){
                    console.log('goBack',data)
                });
            },
            onClick2(){
                window.webkit.messageHandlers["goBack"].postMessage({})
            },
            onClick3(){
                window.webkit.messageHandlers["iphoneX"].postMessage({});
            },
            onClick4(){
                this.CallApp('iphoneX',{},'iosPushBangScreen',data=>{
                    console.log('iphoneX',data)
                });

                window.iosPushBangScreen = data =>{
                     console.log("aaa==",data)
                };

            },
            CallApp(name, params,funcName, callback) {
                window.webkit.messageHandlers[name].postMessage(params);
                window[funcName] = function(obj) {
                    callback(obj);
                };

            }
        }
    }
</script>

<style scoped>

</style>
